package com.smallkingson.ylib.core.utils;

import android.content.Context;
import android.content.res.AssetManager;

import com.smallkingson.ylib.core.Yr;

import java.io.File;

/**
 * Created by 52720 on 2017/8/28.
 */

public class YJNILoader {
    public static boolean loadFormAssets(Context context,String libDirName) {
        try {
            File toLibDir =context. getDir(libDirName, Context.MODE_PRIVATE);
            AssetManager assets = context.getAssets();
            String[] abis = assets.list(libDirName);
            for (String abi : abis) {
                File to = new File(toLibDir + "/" + abi);
                if (!to.exists()) {
                    to.mkdirs();
                }
                String[] soNames = assets.list(libDirName + "/" + abi);
                for (String soName : soNames) {
                    File tofile = new File(to, soName);
                    YFiles.copyFile(assets.open(libDirName + "/" + abi + "/" + soName), tofile);
                    System.load(tofile.toString());
                }
            }
            return true;
        } catch (Exception e) {
            Yr.logError(e);
        }
        return false;
    }
}
